var backstage_domain = "http://localhost:8088";

function myajax(url, type, data, success, error, async) {
    if (data == undefined) {
        data = {}
    }
    if (success == undefined) {
        success = function () {
        }
    }
    if (error == undefined) {
        error = function () {
        }
    }
    if (async == undefined) {
        async = true;
    }
    $.ajax({
        headers: {
            "Authorization": localStorage.getItem("backstage_token")
        },
        async: async,
        url: backstage_domain + url,//提交的路径
        type: type,//提交方式
        data: data,//查询的参数
        dataType: "json",//返回的类型  Text文本
        success: function (result, response, xhr) {
            let token = xhr.getResponseHeader("Authorization");
            if (token != null) {
                localStorage.setItem("backstage_token", token);
            }
            if (result.status == 403) {
                window.location.href = "/html/login.html";
            } else {
                success(result);
            }
        },
        error: error
    });
}


function upLoadImg(selector, success, error, ismultiple) {
    if (success == undefined) {
        success = function () {
        }
    }
    if (error == undefined) {
        error = function () {
        }
    }
    var url = backstage_domain + "/backstage/uploadimg.json";
    if (ismultiple != undefined) {
        url = backstage_domain + "/backstage/multipleuploadimg.json";
    }
    var data = new FormData($(selector)[0]);
    $.ajax({
        headers: {
            "Authorization": localStorage.getItem("backstage_token")
        },
        url: url,
        type: "post",
        data: data,
        dataType: "json",
        processData: false,// 不处理数据
        contentType: false, // 不设置内容类型
        success: function (result, response, xhr) {
            let token = xhr.getResponseHeader("Authorization");
            if (token != null) {
                localStorage.setItem("backstage_token", token);
            }
            success(result);
        },
        error: error
    })
}